package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialCultureService;
import com.ph.irp.model.PBaseAssistantmaterialCulture;

public class AssistantmaterialCultureAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8787503271764336187L;
	/** 文化程度service */
	private PBaseAssistantmaterialCultureService cultureService = null;
	/** 用于存储查询信息的culture */
	private PBaseAssistantmaterialCulture culture = null;

	/** 用于存储查询出的文化程度-culture信息 */
	private List<PBaseAssistantmaterialCulture> cultureList = null;
	/** 用于存储选中的文化程度信息 */
	private String[] rowlist = null;
	private String FORWARD;

	public PBaseAssistantmaterialCultureService getCultureService() {
		return cultureService;
	}

	public void setCultureService(
			PBaseAssistantmaterialCultureService cultureService) {
		this.cultureService = cultureService;
	}

	public PBaseAssistantmaterialCulture getCulture() {
		return culture;
	}

	public void setCulture(PBaseAssistantmaterialCulture culture) {
		this.culture = culture;
	}

	public List<PBaseAssistantmaterialCulture> getCultureList() {
		return cultureList;
	}

	public void setCultureList(List<PBaseAssistantmaterialCulture> cultureList) {
		this.cultureList = cultureList;
	}

	public String[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(String[] rowlist) {
		this.rowlist = rowlist;
	}

	public String addCulture() throws Throwable {
		cultureService.addCulture(culture);
		FORWARD = "success";
		return FORWARD;
	}

	public String deleteCulture() throws Throwable {
		cultureService.deleteCulture(rowlist);
		FORWARD = "success";
		return FORWARD;
	}

	public String updateCultureInput() throws Throwable {
		int cultureId = Integer.valueOf(rowlist[0]);
		culture = cultureService.getCultureById(cultureId);
		FORWARD = "success";
		return FORWARD;
	}

	public String updateCulture() throws Throwable {
		cultureService.updateCulture(culture);
		FORWARD = "success";
		return FORWARD;
	}

	public String getCultures() throws Throwable {
		if (culture == null)
			cultureList = cultureService.getAllCultures();
		else if (!culture.getCultureCode().trim().equals("")
				&& !culture.getCultureName().trim().equals(""))
			cultureList = cultureService.getCulturesByCodeAndName(culture
					.getCultureCode(), culture.getCultureName());
		else if (!culture.getCultureCode().trim().equals(""))
			cultureList = cultureService.getCulturesByCode(culture
					.getCultureCode());
		else if (!culture.getCultureName().trim().equals(""))
			cultureList = cultureService.getCulturesByNmae(culture
					.getCultureName());
		else
			cultureList = cultureService.getAllCultures();
		culture = null;
		FORWARD = "success";
		return FORWARD;
	}

	public String selectCulture() throws Throwable {
		cultureList = cultureService.getCultures(culture);
		culture = null;
		FORWARD = "success";
		return FORWARD;
	}

	public String showCultureList() throws Throwable {
		culture = null;
		return this.getCultures();
	}

}
